home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr05 / ew120.zip / FILES1.ZIP / ANSIOEM.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-02  |  4KB  |  133 lines

  1. {************************************************}
  2. {                                                }
  3. { E! for Windows                                 }
  4. { (c) - Patrick Philippot - 1992,1993            }
  5. {                                                }
  6. { Sample Extension DLL - version 1.1             }
  7. {                                                }
  8. { This DLL translates the current text from      }
  9. { ANSI to OEM or from OEM to ANSI.               }
  10. {                                                }
  11. {************************************************}
  12.  
  13. (*
  14. ANSIOEM is a utility intended for people who have inadvertently loaded
  15. an ANSI file while the current font is OEM or inversely, who have loaded
  16. an ASCII file while the current font is ANSI.
  17.  
  18. To use this DLL simply load it from the user menu or add its name to the
  19. list of autoloaded Extension DLLs using the Autoload dialog box from
  20. the User Menu of EW. That's all.
  21.  
  22. This Extension DLL uses no hook. Since it attaches itself to the User Menu,
  23. you don't need to run it from the User|Execute Extension Menu. Two new
  24. options, "Convert to OEM" and "Convert to ANSI", will automatically appear
  25. in the User Menu.
  26.  
  27. This DLL uses the Menu Dispatching feature. It shows you how multiple
  28. entries can be added from a single Extension DLL to the User Menu.
  29.  
  30. ANSIOEM is intended to be triggered from the User Menu or attached to a
  31. keystroke. When executed from anywhere else, including from another
  32. Extension DLL, the Execute function will receive a null parameter. In that
  33. case, the function will prompt the user to know which kind of conversion
  34. should be applied.
  35.  
  36. If you want to attach this User Extension to a keystroke, please use
  37. Routine Id = 1 for the ANSI to OEM translation and Routine Id = 2 for the OEM
  38. to ANSI translation (this value can be set from the key assignment dialog box).
  39.  
  40. Please see explanations about the Menu Dispatching feature in the EW API
  41. documentation.
  42. *)
  43.  
  44. {$I compdir.inc}
  45. {$C MOVEABLE PRELOAD DISCARDABLE}
  46.  
  47. library Ansi2Oem;
  48.  
  49. uses WinProcs, WinTypes, EWApiImp, Strings;
  50.  
  51. const
  52.   OemTitle : PChar = 'Convert to OEM';
  53.   AnsiTitle : PChar = 'Convert to ANSI';
  54.   OemId = 1;   { Routine Id for Ansi to Oem translation }
  55.   AnsiId = 2;  { Routine Id for Oem to Ansi translation }
  56.  
  57. var
  58.   SaveExit    : Pointer;  { Save ExitProc }
  59.   OemEntryId,             { Entry Id for the "Convert to Oem" menu }
  60.   AnsiEntryId : longint;  { Entry Id for the "Convert to Ansi" menu }
  61.  
  62. function Convert(bOem : boolean) : integer;
  63.  
  64. var
  65.   index : integer;
  66.   P     : PChar;
  67.  
  68. begin
  69.   for index := 0 to Pred(EWGetLineCount) do begin
  70.  {-Convert every line of text}
  71.     P := EWGetLineAt(index);
  72.     if bOem then
  73.       AnsiToOem(P, P)
  74.     else
  75.       OemToAnsi(P, P);
  76.   end;
  77.   Convert := 0; {-Function always successful}
  78. end;
  79.  
  80. function EWExecute(RoutineId : word) : integer; export;
  81.  
  82. var
  83.   H  : hWnd;
  84.   result,
  85.   rc : integer;
  86.  
  87. begin
  88.   rc := -1;
  89.   if RoutineId = 0 then begin
  90.   {-We don't know which type of conversion is requested}
  91.     result := MessageBox(GetFocus, 'Convert To OEM ?', 'OEM/ANSI Conversion', mb_IconQuestion or mb_YesNoCancel);
  92.     if (result = idYes) or (result = idNo) then
  93.       rc := Convert(result = idYes)
  94.     else begin
  95.       EWWriteMessage('Translation cancelled');
  96.       EWExecute := 0;
  97.       Exit;
  98.     end;
  99.  {-Otherwise we call the relevant conversion function}
  100.   end else
  101.     rc := Convert(RoutineId = OemId);
  102.   if rc  = 0 then begin
  103.    {-The window must now be repainted}
  104.     H := EWGetTextWindowHandle;
  105.     InvalidateRect(H, nil, false);
  106.     UpdateWindow(H);
  107.     EWWriteMessage('Text converted');
  108.     EWSetModified; {-Signal to E! that the current text has been modified}
  109.   end else
  110.     EWWriteMessage('Error in Execution'); {-Should not occur}
  111.   EWExecute := rc;
  112. end;
  113.  
  114. procedure LibExit; far;
  115. begin
  116.  {-Remove menu items from the User Menu before unloading}
  117.   EWRemoveMenuEntry(OemEntryId);
  118.   EWRemoveMenuEntry(AnsiEntryId);
  119.   ExitProc := SaveExit;
  120. end;
  121.  
  122. exports
  123.   EWExecute     index 1;
  124.  
  125. begin
  126.   SaveExit := ExitProc;
  127.   ExitProc := @LibExit;
  128.  {-Extension attaches itself to the user Menu}
  129.  { Two commands are made available. Therefore we create two menu entries}
  130.   OemEntryId  := EWAddMenuEntry('ansioem', OemTitle, 0, EWMNU_Extension, OemId);
  131.   AnsiEntryId := EWAddMenuEntry('ansioem', AnsiTitle, 0, EWMNU_Extension, AnsiId);
  132. end.
  133.